package cn.kmsoft.spatialboot.controller;

import cn.kmsoft.common.RestResponse;
import cn.kmsoft.spatialboot.service.RegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE;

/**
 * @author linglei
 * @date 2018/1/4.
 */
@RestController
@Api(description = "区划查询", tags = "3.Region Query")
@RequestMapping(produces = APPLICATION_JSON_VALUE)
public class RegionQueryController {

    private final RegionService regionService;

    @Autowired
    public RegionQueryController(RegionService regionService) {
        this.regionService = regionService;
    }

    @ApiOperation(value = "根据区划代码获取下级区划")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "instanceName", value = "实例名", paramType = "path", required = true),
            @ApiImplicitParam(name = "code", value = "区划代码", paramType = "path", required = true)
    })
    @RequestMapping(value = "/region/{instanceName}/{code}", method = RequestMethod.GET)
    public RestResponse query(@PathVariable String instanceName, @PathVariable String code) {
        return RestResponse.succeed(regionService.queryRegion(instanceName, code));
    }
}
